﻿@{
    Layout = null;
}

<html class="x-admin-sm">
<head>
    <meta name="viewport" content="width=device-width" />
    <meta charset="UTF-8">
    <title>存货Bom数据管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link href="~/X-admin/css/font.css" rel="stylesheet" />
    <script src="~/X-admin/lib/layui/layui.js"></script>
    <link href="~/X-admin/css/xadmin.css" rel="stylesheet" />
    <script src="~/X-admin/js/jquery.min.js"></script>
    <script src="~/X-admin/js/xadmin.js"></script>
    <script src="~/js/framework/sysframework.js"></script>
    <script src="~/js/framework/Common.js"></script>

    <script type="text/html" id="barDemo">
       
        <a title="修改" href="javascript:;" lay-event="edit" id="frmEdit"><i class="layui-icon">&#xe642;</i></a>
        <a title="删除" href="javascript:;" lay-event="del" id="frmDel"><i class="layui-icon">&#xe640;</i></a>
   
    </script>
</head>
<body>
    <div class="layui-fluid">
        <div id="bDiv">
        </div>
        <div class="layui-row layui-col-space15">
            <div class="layui-col-md12">
                <div class="layui-card">
                    <div class="layui-card-body ">
                        <form class="layui-form layui-col-space5" name="qForm" id="qForm">

                            <div class="layui-inline layui-show-xs-block">
                                <input type="text" name="bomCode" placeholder="Bom编码" autocomplete="off" class="layui-input" id="bomCode">
                            </div>
                            <div class="layui-inline layui-show-xs-block">
                                <input type="text" name="relationCode" placeholder="存货编码" autocomplete="off" class="layui-input" id="relationCode">
                            </div>
                            <div class="layui-inline layui-show-xs-block">
                                <input type="text" name="proName" placeholder="存货名称" autocomplete="off" class="layui-input" id="proName">
                            </div>
                           <div class="layui-inline layui-show-xs-block">
                                <input type="text" name="spec" placeholder="规格" autocomplete="off" class="layui-input" id="spec">
                            </div>
                        </form>
                    </div>


                    <div class="layui-card-body layui-table-body layui-table-main">
                        <table class="layui-hide" id="list" lay-filter="list"></table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</body>
</html>

<script type="text/javascript">
    var webCode = "";
    $(function () {
        webCode = getUrlVariable("menuCode");
        BannerData(webCode, "bDiv");
        loadData();
        layui.use('form', function () {
            var form = layui.form;
  
            form.render();
        });
    })
    /**
    加载数据
    **/
    function loadData() {
        layui.use('table', function () {
            var condition = JSON.stringify(FormToJson("qForm"));
            var table = layui.table;
            //给table赋值
            table.render({
                elem: '#list'
                , url: '../Basic/GetDataList?condition=' + condition + "&dataType=bom" //数据接口
                , title: '数据列表'
                , page: true //开启分页
                , even: true
                , limits: [20, 30, 40]
                , limit: 20 //每页默认显示的数量
                , cols: [[ //表头
                      { field: 'id', title: '序号', width: 110}
                    , { field: 'bomCode', title: 'BOM编码', width: 150}
                    , { field: 'relationCode', title: '关联存货编码', width: 150 }
                    , { field: 'proName', title: '关联存货名称', width: 250 }
                    , { field: 'spec', title: '规 格', width: 150 }
                    , { field: 'memo', title: '备注说明', width: 150 }
                    , { fixed: 'right', title: '操作', width: 100, align: 'center', toolbar: '#barDemo' }
                ]],
                done: function (res, curr, count) {
                    $("[data-field='id']").css('display', 'none');//隐藏列
                    currPage = curr;
                }
            });

            //监听行工具事件
            table.on('tool(list)', function (obj) { //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
                var data = obj.data //获得当前行数据
                    , layEvent = obj.event; //获得 lay-event 对应的值
                if (layEvent == 'edit') {
                    InfoOpenPage('../Basic/BomUpdate?bomCode=' + data.bomCode, data.bomCode + "-详情", "85%", "80%",true);
                }
                else if (layEvent == 'del') {
                    layer.confirm('确定要删除选中BOM？', function (index) {
                        var info = DelData(data.bomCode);
                        if (info.result) {
                            obj.del();
                        } else {
                            layer.msg(info.message);
                        }
                        layer.close(index);
                    });

                }
            });
            //监听单元格编辑
            table.on('edit(list)', function (obj) {
                var value = obj.value //得到修改后的值
                    , data = obj.data //得到所在行所有键值
                    , field = obj.field; //得到字段
                $.ajax({
                    url: "../Basic/EditCommonNames",
                    data: { dataId: data.id, names: value },
                    type: "post",
                    success: function (data) {
                        if (!data.Result) {
                            layer.msg(data.Message);
                        }

                    }
                })

            });

        });
    }

    function addWin() {
        InfoOpenPage("../Basic/BomUpdate?bomCode=", "BOM数据更新", "85%", "90%");
    }
    function DelData(bomCode) {
        var info = undefined;
        $.ajax({
            url: "../Basic/DelBomInfoByCode",
            data: { bomCode: bomCode },
            dataType: "json",
            type: "POST",
            async: false,
            success: function (data) {

                info = data;
            }
        });
        return info;
    }
</script>
